<template>
  <div class='container'>
  <!-- 预览文章弹框 -->
  <div class="title">
    <h2>{{articleDetail.title}}</h2>
    <div class="info">
      <span>{{articleDetail.createTime | format}}</span>
      <span>{{article.username}}</span>
      <span class="el-icon-view"></span>
      <span>{{articleDetail.visits}}</span>
    </div>
  </div>
  <div class="content" v-html="articleDetail.articleBody">
  </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { detail } from '@/api/hmmm/articles'
export default {
  name: 'ArticlesPreview',
  props: {
    article: {
      type: Object,
      required: true
    }
  },
  filters: {
    format (value) {
      return dayjs(value).format('YYYY-MM-DD hh:mm:ss')
    }
  },
  data () {
    return {
      articleDetail: {}
    }
  },

  created () {
    this.detail()
  },
  methods: {
    // 通过id获取文章详情
    async detail () {
      const res = await detail(this.article)
      // console.log(res)
      this.articleDetail = res.data
    }
  }
}
</script>

<style scoped lang='scss'>
.container {
  padding: 0 10px;
}
.info {
  padding-bottom: 10px;
  margin-bottom: 20px;
  border-bottom:1px dashed #ccc;
  span {
  margin: 0 5px;
}
}
.content {
  background-color: #f5f5f5;
}
</style>
